/**
 * VTypes 扩展类;
 * @author    KeJun Zheng
 * @copyright (c) 2013,  WayLink
 * @version   0.1
 * @date      <ul>
 * <li>2013-08-07</li>
 * </ul>
 *
 */
var $vtypes=Ext.form.VTypes;

$vtypes.daterange=function(val, field)  {  
        var date = field.parseDate(val);  
      
        // We need to force the picker to update values to recaluate the disabled dates display  
        var dispUpd = function(picker) {  
            var ad = picker.activeDate;  
            picker.activeDate = null;  
            picker.update(ad);  
        };  
      
        if (field.startDateField)  {  
            var sd = Ext.getCmp(field.startDateField);  
            sd.maxValue = date;  
            if (sd.menu && sd.menu.picker)   
            {  
                sd.menu.picker.maxDate = date;  
                dispUpd(sd.menu.picker);  
            }  
        }   
        else if (field.endDateField)  {  
            var ed = Ext.getCmp(field.endDateField);  
            ed.minValue = date;  
            if (ed.menu && ed.menu.picker)  {  
                ed.menu.picker.minDate = date;  
                dispUpd(ed.menu.picker);  
            }  
        }  
        return true;  
    };  
    
    $vtypes.password= function(val, field) {  
        if (field.initialPassField) {  
            var pwd = Ext.getCmp(field.pwdField);  
            return (val == pwd.getValue());   
        }  
        return true;  
  };  
  $vtypes.passwordText= '两次输入的密码不一致！'; 
    
  $vtypes.chinese=function(val,field)  {  
        var reg = /[\u4e00-\u9fa5]/;  
        if(!reg.test(val)) {  
            return false;  
        }  
        return true;  
  }; 
  $vtypes.chineseText='请输入中文';
    
  $vtypes.adault=function(val,field) {  
        try  {  
            if(parseInt(val) >= 18 && parseInt(val) <= 100)  
                return true;  
            return false;  
        }  catch(err)  {  
            return false;  
        }  
  },  
  $vtypes.adaultText='成人年龄输入有误';
    
  $vtypes.age=function(val,field) {  
        try  {  
            if(parseInt(val) >0 && parseInt(val) <= 100)  
                return true;  
            return false;  
        }  catch(err)  {  
            return false;  
        }  
  }; 
  $vtypes.ageText='年龄输入有误';  
    
  $vtypes.max=function(val,field) {  
        try   {  
            if(parseFloat(val) <= parseFloat(field.max))  
                return true;  
            return false;  
        } catch(e) {return false;}  
  };
  $vtypes.maxText='超过最大值'; 
    
  $vtypes.min=function(val,field)   {  
        try  {  
            if(parseFloat(val) >= parseFloat(field.min))  
                return true;  
            return false;  
        } catch(e) {return false;}  
  };
  $vtypes.minText='小于最小值';
        
  $vtypes.datecn=function(val,field)  {  
        try  {  
            var regex = /^(\d{4})-(\d{2})-(\d{2})$/;  
            if(!regex.test(val)) return false;  
            var d = new Date(val.replace(regex, '$1/$2/$3'));  
            return (parseInt(RegExp.$2, 10) == (1+d.getMonth())) && (parseInt(RegExp.$3, 10) == d.getDate())&&(parseInt(RegExp.$1, 10) == d.getFullYear());  
        } catch(e) {return false;}  
  }; 
  $vtypes.datecnText='请使用这样的日期格式: yyyy-mm-dd. 例如:2008-06-20.'; 
    
  $vtypes.integer=function(val,field) {  
        try {  
            if(/^[-+]?[0-9]+$/.test(val))  
                return true;  
            return false;  
        } catch(e) {return false;}  
  };
  $vtypes.integerText='请输入正确的整数';
    
  $vtypes.minlength=function(val,field) {  
        try {  
            if(val.length >= parseInt(field.minlen))  
                return true;  
            return false;
        } catch(e) {return false;}  
  };
  $vtypes.minlengthText='长度过小';
    
  $vtypes.maxlength=function(val,field) {  
     try {  
        return val.length <= parseInt(field.maxlen) ;
     } catch(e) {return false;}  
  };
  $vtypes.maxlengthText='长度过大'; 
    
  $vtypes.ip=function(val,field) {  
        try {  
            if((/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/.test(val)))  
                return true;  
            return false;  
        } catch(e) {return false;}  
  }; 
  $vtypes.ipText='请输入正确的IP地址'; 
    
  $vtypes.phone=function(val,field) {  
        try  {  
            if(/^(((0[1-9]{3})|(0[12][0-9]))?[-])?[1-9][0-9]{6,7}$/.test(val))  
                return true;  
            return false;  
        } catch(e) {return false;}  
  };  
  $vtypes.phoneText='请输入正确的电话号码,如:0920-29392929';  
    
  $vtypes.mobilephone=function(val,field) {  
        try {  
            if(/^0?[1][3578][0-9]{9}$/.test(val))  
                return true;  
            return false;  
        } catch(e) {return false;}  
  }; 
  $vtypes.mobilephoneText='请输入正确的11位手机号码';  
    
  $vtypes.alpha=function(val,field)  {  
        try  {  
            if( /^[a-zA-Z]+$/.test(val))  
                return true;  
            return false;  
        } catch(e) {return false;}  
  }; 
  $vtypes.alphaText='请输入英文字母';
  $vtypes.alphanumText='请输入英文字母或是数字,其它字符是不允许的.'; 
  $vtypes.urlText='请输入有效的URL地址.';


